package com.twq.types.typeparam.contravariance

/**
 * Created by tangweiqun on 2017/12/6.
 */
class Publication(val title: String)

class Book(title: String) extends Publication(title)

/**
 * trait Function1[-S, +T] {
 * def apply(x: S): T
 * }
 */
object Library {
  val books: Set[Book] =
    Set(
      new Book("Programming in Scala"),
      new Book("Walden")
    )

  def printBookList(info: Book => AnyRef) = { //Book => AnyRef  ===> Function1[Book, AnyRef]
    for (book <- books) println(info(book)) //toString
  }
}

object Customer extends App {
  def getTitle(p: Publication): String = p.title // Publication => String   ===> Function1[Publication, String]

  Library.printBookList(getTitle) // Publication => String 是 Book => AnyRef的子类
}

